<template>
	<yd-layout id='faqDetail' class=''>
		<div class="content">
			<div class="title">{{dataObj.question}}</div>
			<div class="content_bottom">
				<div style="white-space: pre-line;" class="faq_content">{{dataObj.answer}}</div>
				
				<!--<div class="faq_time">时间：2019年6月13日</div>
				<div class="faq_area" >地点：大大阿达的</div>-->
				<div class="faq_btn">
					<div class="faq_btn_left">
						<div v-if="dataObj.liked!=1" @click="zanClick" class="faq_btn_c">
							<img src="../../assets/faqDetail_1.png" alt="" />
							<div>有用</div>
						</div>
						<div v-else class="faq_btn_c" @click="zanClick">
							<img src="../../assets/faqDetail_2.png" alt="" />
							<div>{{dataObj.like_count>10000?(dataObj.like_count/10000).toFixed(2):dataObj.like_count}}{{dataObj.like_count>10000?'万':''}}人</div>
						</div>
					</div>
					<div class="faq_btn_right faq_btn_left">
						<div class="faq_btn_c" v-if="dataObj.collected != 1" @click="scClick">
							<img src="../../assets/faqDetail_3.png" alt="" />
							<div>收藏</div>
						</div>
						<div class="faq_btn_c" v-else @click="scClick">
							<img src="../../assets/faqDetail_4.png" alt="" />
							<div>已收藏</div>
						</div>
					</div>
				</div>
			</div>
				
		</div>
	</yd-layout>
</template>

<script>
	export default{
		components:{
			
		},
		data(){
			return {
				
				dataObj:{},
			}
		},
		created() {
		},
		watch: {
			
		},
		computed: {
			
		},
		mounted(){
			document.title='常见问题解析'
			this.getFaqDetail()
		},
		methods:{
			getFaqDetail(){
				this.$root.ajax({
					name: 'Qa/detail',
//					noToken:true,
					params: {
						id:this.$route.query.id
					}
				}).then((d) => {
					d.data.newTime = this.$root.getDate(new Date(d.data.answer_time*1000))
					this.dataObj = Object.assign({},this.dataObj,d.data);
					console.log(this.dataObj )
					
					//分享
						if(this.$root.isWeiXin()){
							//分享
							let query = '';
							if(this.$root.config.channel){
							 	query = `params=channelDY2FGoldUrlStrDY${this.$route.name}FGkeyNumDY1FGparamsKey1DYidFGparamsVal1DY${d.data.id}`
							}else{
							 	query = `params=oldUrlStrDY${this.$route.name}FGkeyNumDY1FGparamsKey1DYidFGparamsVal1DY${d.data.id}`
							}
							let obj={
								title:this.dataObj.question,
								title_img:this.$root.config.shareImgLogo
							}
							this.$root.wxShare({
								d:obj,//分享对象，题目等{title:'',title-img:''}
								query: query,//参数
								desc:this.dataObj.answer//分享详情
							})
						}
				})
			},
			scClick(){
				let name = 'collection/collect'
				if(this.dataObj.collected==1){
					name = 'collection/cancel' //取消点赞
				}
				this.$root.ajax({
					name: name,
					params: {
						oid:this.dataObj.id,
						kind:7,
					}
				}).then((d) => {
					if(this.dataObj.collected==1){
						this.$set(this.dataObj,'collected',0)
					}else{
						this.$set(this.dataObj,'collected',1)
					}
					this.$dialog.toast({
	                    mes: '操作成功',
	                    timeout: 1500
	                });
				})
			},
			zanClick(){
				let name = 'like/like'
				if(this.dataObj.liked==1){
					name = 'like/unlike' //取消点赞
				}
				this.$root.ajax({
					name: name,
					params: {
						oid:this.dataObj.id,
						kind:7,
					}
				}).then((d) => {
					if(this.dataObj.liked==1){
						this.$set(this.dataObj,'liked',0)
						this.$set(this.dataObj,'like_count',this.dataObj.like_count - 1)
					}else{
						this.$set(this.dataObj,'liked',1)
						this.$set(this.dataObj,'like_count',this.dataObj.like_count + 1)
					}
					
					this.$dialog.toast({
	                    mes: '操作成功',
	                    timeout: 1500
	                });
				})
			},
		}
	}
</script>

<style lang="scss">
	@import './faqDetail.scss';
</style>